package com.wx.controller;

import com.alibaba.fastjson.JSONObject;
import com.wx.model.PageModel;
import com.wx.model.RecruitmentModel;
import com.wx.service.IRecruitmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/back/recruitment")
public class RecruitmentController {
    @Autowired
    IRecruitmentService iRecruitmentService;

    @RequestMapping("/condiationFindAll")
    public JSONObject condiationFindAll(@RequestBody RecruitmentModel recruitmentModel){
//        PageModel pageModel =recruitmentModel.getPageModel();
//        pageModel.setPageNum(pageModel.getPageNum()==null || "".equals(pageModel.getPageNum())? 1 :(pageModel.getPageNum()));
//        pageModel.setPageSize(pageModel.getPageSize()==null || "".equals(pageModel.getPageSize()) ? 10:(pageModel.getPageSize()));
        List<RecruitmentModel> list=iRecruitmentService.condiationFindAll(recruitmentModel);
        int number=iRecruitmentService.getcount(recruitmentModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        jsonObject.put("number",number);
        return jsonObject;
    }

    @RequestMapping("/recruitmentAdd")
    public JSONObject recruitmentAdd(@RequestBody RecruitmentModel recruitmentModel){
        int count=iRecruitmentService.recruitmentAdd(recruitmentModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("count",count);
        return jsonObject;
    }

    @RequestMapping("/recruitmentFindById")
    public JSONObject recruitmentFindById(@RequestBody RecruitmentModel recruitmentModel){
        RecruitmentModel recruitmentModel1=iRecruitmentService.recruitmentFindById(recruitmentModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("recruitmentModel",recruitmentModel1);
        return jsonObject;
    }


    @RequestMapping("/recruitmentUpdate")
    public JSONObject recruitmentUpdate(@RequestBody RecruitmentModel recruitmentModel){
        int count=iRecruitmentService.recruitmentUpdate(recruitmentModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("count",count);
        return jsonObject;
    }


    @RequestMapping("/recruitmentDeleteById")
    public JSONObject recruitmentDeleteById(@RequestBody RecruitmentModel recruitmentModel){
        int count=iRecruitmentService.recruitmentDeleteById(recruitmentModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("count",count);
        return jsonObject;
    }
}
